var e = require;
var t = module;
var n = i(e("RecorderPanel")),
o = i(e("SoundMgr"));
function i(e) {
    return e && e.__esModule ? e: {
        default: e
    }
}
window.NPCKingController = {
    Instance: null
};
var a = e("LevelManager"),
r = e("DeathController");
cc.Class({
    extends: cc.Component,
    properties: {
        DeathController: r,
        ControllerAnimation: dragonBones.ArmatureDisplay,
        _CurrentIsDiscover: !1,
        CurrentIsDiscover: {
            get: function() {
                return this._CurrentIsDiscover
            },
            set: function(e) {
                this._CurrentIsDiscover = e;
                this.onControllerDiscoverStatusChange()
            }
        }
    },
    onLoad: function() {
        NPCKingController.Instance = this
    },
    start: function() {
        CameraManager.Instance.CameraTarget = this.node;
        this.ControllerAnimation.addEventListener(dragonBones.EventObject.START,
        function() {
            "back" == this.ControllerAnimation.animationName && this.AFUNC_LeftLook()
        }.bind(this), this);
        this.scheduleOnce(this.RandomKingAnims, 2)
    },
    onDestroy: function() {
        NPCKingController.Instance = null
    },
    update: function(e) {
        n.default.GamePause || LevelManager.Instance.AllowAvatarControllerMove && (this.node.x += LevelManager.Instance.AvatarControllerMoveSpeed * e)
    },
    Death: function(e) {
        this.DeathController.DeathFunction(e);
        this.node.destroy()
    },
    RandomKingAnims: function() {
        this.unschedule(this.RandomKingAnimsCallback);
        this.RandomKingAnimsCallback = this.scheduleOnce(function() {
            this.RandomKingAnims()
        },
        Math.round(Math.round(5 * Math.random() + 3)));
        if (! (KillerController.Instance.node.position.sub(this.node.position).mag() >= LevelManager.Instance.AvatarControllerDistanceMinLimit || LevelManager.Instance.AttackProgressBar.progress >= .82 || this.CurrentIsDiscover)) {
            this.ControllerAnimation.playAnimation("walk", 0);
            var e = Math.round(Math.round(14 * Math.random()));
            e >= 0 && e <= 2 ? this.ControllerAnimation.playAnimation("walk", 0) : e >= 3 && e <= 4.5 ? this.ControllerAnimation.playAnimation("back", 1) : e >= 6 && e <= 6.8 ? this.ControllerAnimation.playAnimation("back", 1) : e >= 8 && e <= 8.8 ? this.ControllerAnimation.playAnimation("back", 1) : e >= 10 && e <= 12 && this.ControllerAnimation.playAnimation("back", 1)
        }
    },
    AFUNC_LeftLook: function() {
        if (! (LevelManager.Instance.AttackProgressBar.progress >= .82 || this.CurrentIsDiscover)) {
            cc.log("llook func");
            o.default.Instance.playSoundClip(AssetManager.Instance.AudioClips[7]);
            LevelManager.Instance.AllowAvatarControllerMove = !1;
            LevelManager.Instance.GameAllowOperation = !1;
            this.CurrentIsDiscover = !0;
            this.unschedule(this.AFUNC_LeftLookOverCallback);
            this.AFUNC_LeftLookOverCallback = this.scheduleOnce(this.AFUNC_LeftLookOver, Math.round(Math.round(2 * Math.random() + 2)))
        }
    },
    AFUNC_LeftLookOver: function() {
        if (! (LevelManager.Instance.AttackProgressBar.progress >= .9) && LevelManager.Instance.GameCurrentOperationScene != a.GameSceneBlockType.Jail) {
            cc.log("llookover");
            LevelManager.Instance.AllowAvatarControllerMove = !0;
            LevelManager.Instance.GameAllowOperation = !0;
            this.ControllerAnimation.playAnimation("walk", 0);
            this.CurrentIsDiscover = !1
        }
    },
    AFUNC_Cough: function() {
        o.default.Instance.playSoundClip(AssetManager.Instance.AudioClips[2])
    },
    onControllerDiscoverStatusChange: function() {
        this.CurrentIsDiscover ? LevelManager.Instance.AttackProgressBar.progress > 0 ? KillerController.Instance.onNonSafeKingDiscoverFunction() : KillerController.Instance.onSafeKingDiscoverFunction() : KillerController.Instance.onSafeKingDiscoverFunctionOver()
    },
    onJailSceneFinish: function() {
        this.AFUNC_LeftLookOver()
    }
})